import java.io.*;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        while(true){
            System.out.println("=======图书管理系统======");
            System.out.println("1.查询");
            System.out.println("2.录入");
            System.out.println("3.退出");
            System.out.println("=============");
            System.out.print("请输入操作：");
            int num = scanner.nextInt();

            if(num == 1){
                try(BufferedReader in = new BufferedReader(
                        new InputStreamReader(new FileInputStream("D:\\JAVA学习日志\\Project-library\\menu.txt")))){
                    in
                            .lines()
                            .forEach(System.out::println);
                }catch (IOException e){
                    e.printStackTrace();
                }
            }
            if(num == 2){
                try(OutputStreamWriter writer = new OutputStreamWriter(
                        new FileOutputStream("D:\\JAVA学习日志\\Project-library\\menu.txt", true))){
                    if(check()){
                        writer.write("\n");
                    }
                    String s;
                    Scanner cin = new Scanner(System.in);
                    s=cin.nextLine();
                    writer.write(s);
                }catch (IOException e){
                    e.printStackTrace();
                }
            }
            if(num == 3){
                break;
            }
            if(num==4){

            }
        }
    }

    public static boolean check(){
        try(FileInputStream inputStream = new FileInputStream("D:\\JAVA学习日志\\Project-library\\menu.txt")){
            if(inputStream.available()==0){
                return false;
            }
        }catch (IOException e){
            e.printStackTrace();
        }
        return true;
    }

}